package cn.jiyun.goods.service.impl;

import cn.jiyun.goods.dao.GoodsDao;
import cn.jiyun.goods.feign.WareFeign;
import cn.jiyun.goods.pojo.Goods;
import cn.jiyun.goods.pojo.dto.GoodsDto;
import cn.jiyun.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsDao goodsDao;
    @Autowired
    private WareFeign wareFeign;
    @Override
    public List<Goods> findAll() {
        return goodsDao.selectList(null);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void add(GoodsDto goodsDto) {
        Goods goods = new Goods();
        goods.setName(goodsDto.getName());
        goods.setPrice(goodsDto.getPrice());
        int insert = goodsDao.insert(goods);
        wareFeign.add(insert, goodsDto.getNum());
    }
}
